{include file="public/layout" /}
<body class="bodystyle" style="overflow-y: scroll;min-width:auto;">
<div id="toolTipLayer" style="position: absolute; z-index: 9999; display: none; visibility: visible; left: 95px; top: 573px;"></div>
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page" style="min-width: auto;box-shadow:none;">
    {include file="canal/bar" /}
    <!-- 操作说明 -->
    <div id="explanation" class="explanation" style="color: rgb(44, 188, 163); background-color: rgb(237, 251, 248); width: 99%; height: 100%;">
        <div id="checkZoom" class="title"><i class="fa fa-lightbulb-o"></i>
            <h4 title="提示相关设置操作时应注意的要点">提示</h4>
            <span title="收起提示" id="explanationZoom" style="display: block;"></span>
        </div>
        <ul>
            <li>先完善微信公众号的配置</li>
            <li>微信号、二维码是在微站点开启 <span style="color: red;">强制微信模式</span> 时在PC和移动端展示</li>
        </ul>
    </div>
    <form class="form-horizontal" id="postMicrosite" method="post">
        <div class="ncap-form-default">
            <dl class="row">
                <dt class="tit">
                    <label>微站点模式</label>
                    <input type="hidden" id="shop_micro" value="{$usersConfig.shop_micro|default=0}">
                </dt>
                <dd class="opt" style="line-height: 30px;">
                    <label>
                        <input type="radio" name="shop[shop_micro]" id="shop_micro1" value="1" {if condition="isset($usersConfig.shop_micro) && $usersConfig.shop_micro == 1"} checked="checked" {/if} onclick="DetectConfig(1);"/>开启
                    </label>
                    &nbsp;&nbsp;&nbsp;
                    <label>
                        <input type="radio" name="shop[shop_micro]" id="shop_micro0" value="0" {if condition="empty($usersConfig.shop_micro)"} checked="checked" {/if}/>关闭
                    </label>
                    &nbsp;&nbsp;&nbsp;
                    <p class="notic">开启后，在微信里访问不需要注册或登录，需要先配置下方微信参数</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label>强制微信模式</label>
                    <input type="hidden" id="shop_force_use_wechat" value="{$usersConfig.shop_force_use_wechat|default=0}">
                </dt>
                <dd class="opt" style="line-height: 30px;">
                    <label>
                        <input type="radio" name="shop[shop_force_use_wechat]" id="shop_force_use_wechat1" value="1" {if condition="isset($usersConfig.shop_force_use_wechat) && $usersConfig.shop_force_use_wechat == 1"} checked="checked" {/if} onclick="DetectConfig(2);"/>开启
                    </label>
                    &nbsp;&nbsp;&nbsp;
                    <label>
                        <input type="radio" name="shop[shop_force_use_wechat]" id="shop_force_use_wechat0" value="0" {if condition="empty($usersConfig.shop_force_use_wechat)"} checked="checked" {/if} onclick="DetectConfig(3);"/>关闭
                    </label>
                    &nbsp;&nbsp;&nbsp;
                    <p class="notic">开启后，只能在微信内访问，需要先开启微站点模式</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="wechat_name">公众号的微信号</label>
                </dt>
                <dd class="opt">
                    <input type="text" name="login[wechat_name]" id="wechat_name" value="{$login.wechat_name|default=''}" class="input-txt">
                    <p class="notic"></p>
                </dd>
            </dl>

            <dl class="row">
                <dt class="tit">
                    <label for="wechat_pic">公众号的二维码</label>
                </dt>
                <dd class="opt">
                    <div class="input-file-show">
                        <span class="show">
                            <a id="img_a_wechat_pic" class="nyroModal" rel="gal" href="{$login.wechat_pic|default='javascript:void(0);'}?t={php}echo time();{/php}" target="_blank">
                                <i id="img_i_wechat_pic" class="fa fa-picture-o" {notempty name="$login.wechat_pic"}onmouseover="layer_tips=layer.tips('<img src={$login.wechat_pic|default=''}?t={php}echo time();{/php} width=300 height=300>',this,{tips: [1, '#fff']});"{/notempty} onmouseout="layer.close(layer_tips);"></i>
                            </a>
                        </span>
                        <span class="type-file-box">
                            <input type="text" id="wechat_pic" name="login[wechat_pic]" value="{$login.wechat_pic|default=''}" class="type-file-text" autocomplete="off">
                            <input type="button" name="button" id="button1" value="选择上传..." class="type-file-button">
                            <input class="type-file-file" onclick="GetUploadify(1, '', 'allimg', 'wechat_pic_call_back')" size="30" hidefocus="true" nc_type="change_site_logo" title="点击前方预览图可查看大图，点击按钮选择文件并提交表单后上传生效">
                        </span>
                    </div>
                    <span class="err"></span>
                    <p class="notic"></p>
                </dd>
            </dl>
            <dl class="row">
                <div class="bot" style="padding-bottom:0px;">
                    <input type="hidden" id="WX_appid" value="{$login.appid|default=''}">
                    <a href="JavaScript:void(0);" onclick="submit_microsite();" class="ncap-btn-big ncap-btn-green">确认提交</a>
                </div>
            </dl>
        </div>
    </form>
</div>
<script type="text/javascript">
    // 提交
    function submit_microsite(){
        layer_loading("正在处理");
        $.ajax({
            url: "{:url('System/microsite', ['_ajax'=>1])}",
            type: 'POST',
            dataType: 'JSON',
            data: $('#postMicrosite').serialize(),
            success: function(res){
                layer.closeAll();
                if (1 == res.code) {
                    layer.msg(res.msg, {shade: 0.1, time: 1000}, function(){
                        window.location.reload();
                    });
                } else {
                    var icon = 2;
                    try{
                        if (res.data.icon) {
                            icon = res.data.icon;
                        }
                    }catch(e){}
                    showErrorAlert(res.msg, icon);
                    return false;
                }
            },
            error: function(e){
                layer.closeAll();
                showErrorMsg(e.responseText);
                return false;
            }
        });
    }

    // 检测是否配置微信参数
    function DetectConfig(type) {
        if (3 == type) {
            $('#shop_micro0').removeAttr("disabled");
            return false;
        }

        var WX_appid = $('#WX_appid');
        if (!WX_appid.val() || '' == WX_appid.val()) {
            if (1 == type) {
                $("#shop_micro0").click();
            } else if (2 == type) {
                $("#shop_force_use_wechat0").click();
            }
            showErrorAlert('请先完善微信公众号配置');
            return false;
        }

        if (2 == type) {
            // 设置微信端开启
            $("#shop_force_use_wechat1, #shop_micro1").attr('checked', true);
            $('#shop_micro0').attr("disabled", "disabled");
        }
    }

    // 加载图片显示
    function wechat_pic_call_back(fileurl_tmp) {
        $("#wechat_pic").val(fileurl_tmp);
        $("#img_a_wechat_pic").attr('href', fileurl_tmp);
        $("#img_i_wechat_pic").attr('onmouseover', "layer_tips=layer.tips('<img src="+fileurl_tmp+" width=300 height=300>',this,{tips: [1, '#fff']});");
    }
</script>
{include file="public/footer" /}